package com.jdk.demo.unsafe;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class CompareAndSwapDemo {
	
	public static void main(String[] args) throws InterruptedException {
		Counter counter = new Counter();
		ExecutorService threadPool = Executors.newFixedThreadPool(100);

		// 起100个线程，每个线程自增10000次
		IntStream.range(0, 100)
		    .forEach(i->threadPool.submit(()->IntStream.range(0, 10000)
		        .forEach(j->counter.increment())));

		threadPool.shutdown();

		Thread.sleep(2000);

		// 打印1000000
		System.out.println(counter.getCount());
	}

}
